package cn.zh.npro.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;

import cn.zh.npro.MyApplication;
import cn.zh.npro.R;

public class Welcom extends BaseActivity {
    MyApplication mapp;
    SharedPreferences sp;
    private Handler handler=new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcom);
        setWindowStatusBarColor(this, R.color.white);
        mapp= (MyApplication) getApplication();
        sp=mapp.getSp();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                gotoLogin();
            }
         },1000);

         }


    private void gotoLogin() {

        if (sp.getBoolean("isload",false)){
            Intent intent=new Intent(Welcom.this,MainActivity.class);
            intent.putExtra("logt","0");
            startActivity(intent);
            finish();
        }else {
            Intent intent=new Intent(Welcom.this,Login.class);
            intent.putExtra("log",1);
            startActivity(intent);
            finish();
         }

       }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
      }

    @Override
    protected void onDestroy() {
        if (handler != null) {
            //If token is null, all callbacks and messages will be removed.
            handler.removeCallbacksAndMessages(null);
        }
        super.onDestroy();
     }

}
